#!/bin/bash
##一键安装docker服务
##此脚本无法独立运行
docker_v(){
	yum list docker-ce --showduplicates|sort -r | awk '{print $2}' | awk 'NR>6{print}'|sed 's/base://'| awk NF |sed 's/3://'
	echo -e "请选择一个docker版本并粘贴\n默认安装最新版"
	read docker_ver
	if [[ -z "$docker_ver" ]];then
		dockers="docker-ce"
	else
		dockers="docker-ce-${docker_ver}"
	fi
}
source THEISPI
docker_install(){
	if [[ "$PI" == "1" ]];then
		docker_v
		yum install -y https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/edge/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm
		yum install -y $dockers
	elif [[ "$PI" == '2' ]];then
		apt-get install -y $1
	fi
	sudo systemctl start docker
	if [[ "$?" == '0' ]];then
		echo 'docker-ce installed'
	else
		echo 'docker-ce  installation failed'
		exit 2
	fi
}
if [[ "$os_s" == "ubuntu" ]];then
	docker_install	docker.io
else
	docker_install docker-ce
fi
if [[ "$?" == '0' ]];then
	mkdir -p /etc/docker/
	sudo systemctl restart docker
	sudo echo -e "{\n\t\"exec-opts\": [\"native.cgroupdriver=systemd\"],\n\t\"registry-mirrors\": [\"http://hub-mirror.c.163.com\"]\n}" > /etc/docker/daemon.json
	sudo systemctl daemon-reload
 	sudo systemctl enable docker
	sudo systemctl restart docker
	if [[ "$?" == '0' ]];then
		echo 'Docker service started successfully'
	else
		echo 'Docker service failed to start'
	fi
	sudo docker info
fi
echo 'Docker completed'
